package de.hauschild.gmltracer.gml.impl.binding;

import de.hauschild.gmltracer.gml.Environment;
import de.hauschild.gmltracer.gml.Token;
import de.hauschild.gmltracer.gml.TokenStack;
import de.hauschild.gmltracer.gml.impl.AbstractToken;

/**
 * Pops the top {@link Token} from the {@link TokenStack} and binds it with its
 * name.
 * 
 * @author Klaus Hauschild
 * @since 1.0.0
 */
public class BinderToken extends AbstractToken {

  private final String name;

  /**
   * Instantiates a new binder token.
   * 
   * @param theName
   *          the name
   */
  public BinderToken(final String theName) {
    name = theName;
  }

  @Override
  public void evaluate(final Environment environment, final TokenStack tokenStack) {
    final Token token = tokenStack.pop(Token.class);
    environment.put(name, token);
  }

  @Override
  public String toString() {
    return "/" + name; //$NON-NLS-1$
  }

}
